//让LED以亮0.25秒->灭0.5秒->亮0.75秒->灭1秒的规律，持续循环闪烁

module fsm2_2 (
    input clk,//27MHz
    input reset,
    output reg led
);

    reg [3:0] state;
    reg [3:0] next_state;

    reg [22:0] cont;//0.25s周期

    parameter contmax=6750000-1;

    always @(posedge clk or negedge reset) begin
        if (reset==0) begin
            cont<=0;
            state<=0;
        end else begin
            if (cont==contmax) begin
                state<=next_state;
                cont<=0;
            end else begin
                cont<=cont+1;
            end
        end
    end
//0 on
//12 off
//345 on 
//6789 off
    always @(state) begin
        case (state)
            0:begin
              led=0;
              next_state=state+1;  
            end
            1:begin
              led=1;
              next_state=state+1;  
            end
            2:begin
              led=1;
              next_state=state+1;  
            end
            3:begin
              led=0;
              next_state=state+1;  
            end
            4:begin
              led=0;
              next_state=state+1;  
            end
            5:begin
              led=0;
              next_state=state+1;  
            end
            6:begin
              led=1;
              next_state=state+1;  
            end
            7:begin
              led=1;
              next_state=state+1;  
            end
            8:begin
              led=1;
              next_state=state+1;  
            end
            9:begin
              led=1;
              next_state=0;  
            end 
            default:next_state=0;
        endcase
    end
endmodule
